#include "ZControlWidget.h"
const int ICONSIZE = 40;
ZControlWidget::ZControlWidget(QWidget *parent)
    : QWidget(parent)
{
    initContent();
    initConnection();
}

void ZControlWidget::initConnection()
{
    connect(pushButtonMotorUp, SIGNAL(pressed()), this, SIGNAL(moveUp()));
    connect(pushButtonMotorDown, SIGNAL(pressed()), this, SIGNAL(moveDown()));
    connect(pushButtonMotorUp, SIGNAL(released()), this, SIGNAL(moveUpStop()));
    connect(pushButtonMotorDown, SIGNAL(released()), this, SIGNAL(moveDownStop()));
    connect(pushButtonStopZ, SIGNAL(pressed()), this, SIGNAL(stop()));
}

void ZControlWidget::initContent()
{
    gridLayout = new QGridLayout;
    gridLayout->setSpacing(1);
    pushButtonMotorUp = new QPushButton(this);
    pushButtonMotorUp->setMinimumSize(QSize(ICONSIZE, ICONSIZE));
    pushButtonMotorUp->setMaximumSize(QSize(ICONSIZE, ICONSIZE));
    QIcon icon;
    icon.addFile(QStringLiteral(":/StageControlCommon/res/up.png"), QSize(), QIcon::Normal, QIcon::Off);
    pushButtonMotorUp->setIcon(icon);
    pushButtonMotorUp->setIconSize(QSize(ICONSIZE, ICONSIZE));
    gridLayout->addWidget(pushButtonMotorUp, 0, 0, 1, 1);

    pushButtonStopZ = new QPushButton(this);
    pushButtonStopZ->setMinimumSize(QSize(ICONSIZE, ICONSIZE));
    pushButtonStopZ->setMaximumSize(QSize(ICONSIZE, ICONSIZE));
    QIcon icon2;
    icon2.addFile(QStringLiteral(":/StageControlCommon/res/stop.png"), QSize(), QIcon::Normal, QIcon::Off);
    pushButtonStopZ->setIcon(icon2);
    pushButtonStopZ->setIconSize(QSize(ICONSIZE, ICONSIZE));

    gridLayout->addWidget(pushButtonStopZ, 1, 0, 1, 1);
    pushButtonMotorDown = new QPushButton(this);
    pushButtonMotorDown->setMinimumSize(QSize(ICONSIZE, ICONSIZE));
    pushButtonMotorDown->setMaximumSize(QSize(ICONSIZE, ICONSIZE));
    QIcon icon4;
    icon4.addFile(QStringLiteral(":/StageControlCommon/res/down.png"), QSize(), QIcon::Normal, QIcon::Off);
    pushButtonMotorDown->setIcon(icon4);
    pushButtonMotorDown->setIconSize(QSize(ICONSIZE, ICONSIZE));
    gridLayout->addWidget(pushButtonMotorDown, 2, 0, 1, 1);

    setLayout(gridLayout);

    QSizePolicy policy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    setSizePolicy(policy);
}
